package main

import (
	"fmt"
	"io"
	"net/http"
)

func draw(w io.Writer) {
	fmt.Fprintf(w, "<svg xmlns='http://www.w3.org/2000/svg' style='stroke: black; fill: red; stroke-width: 1.7' width='1000' height='1000'>\n")
	fmt.Fprintf(w, "<circle cx='100' cy='50' r='40' fill='yellow'/>")
	fmt.Fprintf(w, "<rect x='400' y='200' width='300' height='100' style='fill:rgb(0,0,255);stroke-width:1;stroke:rgb(0,0,0)'/>\n")
	fmt.Fprintf(w, "<ellipse cx='300' cy='80' rx='100' ry='50' style='fill:#eeeeee;stroke:purple;stroke-width:2'/>\n")
	fmt.Fprintf(w, "<line x1='300' y1='350' x2='400' y2='400' style='stroke:rgb(255,0,0);stroke-width:2'/>\n")
	fmt.Fprintf(w, "<polyline points='20,20 40,25 60,40 80,120 120,140 200,180' style='fill:none;stroke:black;stroke-width:3' />\n")
	fmt.Fprintf(w, "<polygon points='%g,%g %g,%g %g,%g' />\n", 10.0, 210.0, 100.0, 400.0, 20.0, 300.0)
	fmt.Fprintf(w, "<path d='M 100 350 q 150 -300  300 0 q 150 -300' stroke='blue' stroke-width='5' fill='none' />")

	// 绘制控制线
	fmt.Fprintf(w, "<path d='M500 500 L500 600' stroke='#000000' fill='none' style='stroke:red;stroke-width: 2px;'/>\n")
	fmt.Fprintf(w, "<path d='M600 600 L700 500' stroke='#000000' fill='none' style='stroke:red;stroke-width: 2px;'/>\n")
	fmt.Fprintf(w, "<path d='M700 500 L800 400' stroke='#000000' fill='none' style='stroke:blue;stroke-width: 2px;'/>\n")
	fmt.Fprintf(w, "<path d='M900 500 L900 600' stroke='#000000' fill='none' style='stroke:red;stroke-width: 2px;'/>\n")
	// 绘制曲线
	fmt.Fprintf(w, "<path d='M500 500 C500 600 600 600 700 500 S900 500 900 600' stroke='#000000' fill='none' style='stroke-width: 2px;'/>\n")
	fmt.Fprintf(w, "</svg>\n")
}

func handle(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "image/svg+xml")
	draw(w)
}

func main() {
	http.HandleFunc("/", handle)
	http.ListenAndServe(":8080", nil)
}
